package mutris.client.handlers;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import mutris.client.MutrisGame;

public class BoardKeyHandler implements KeyListener {

	private MutrisGame game;
	
	public BoardKeyHandler(MutrisGame board) {
		setGame(board);
	}
	
	public MutrisGame getGame() {
		return game;
	}
	
	public void setGame(MutrisGame game) {
		if (null == game) {
			throw new IllegalArgumentException("board must not be null");
		}
		
		this.game = game;
	}
	
	
	@Override
	public void keyTyped(KeyEvent e) {}

	@Override
	public void keyPressed(KeyEvent e) {
		int key = e.getKeyCode(); // Keyboard code for the pressed key.

		if (key == KeyEvent.VK_LEFT) {
			game.moveActiveBlockLeft();
		} else if (key == KeyEvent.VK_RIGHT) {
			game.moveActiveBlockRight();
		} else if (key == KeyEvent.VK_UP) {
			game.rotateActiveBlock();
		} else if (key == KeyEvent.VK_DOWN) {
			game.moveActiveBlockDown();
		} else if (key == KeyEvent.VK_SPACE) {
			game.moveActiveBlockDown(true);
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {}

}
